<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>attachablemenu.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_attachablemenu.js.html">attachablemenu.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Definition of the AttachableMenu class.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.ui.AttachableMenu&#39;);
<a name="line21"></a>
<a name="line22"></a>goog.require(&#39;goog.a11y.aria&#39;);
<a name="line23"></a>goog.require(&#39;goog.a11y.aria.State&#39;);
<a name="line24"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line25"></a>goog.require(&#39;goog.events.KeyCodes&#39;);
<a name="line26"></a>goog.require(&#39;goog.ui.ItemEvent&#39;);
<a name="line27"></a>goog.require(&#39;goog.ui.MenuBase&#39;);
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>
<a name="line31"></a>/**
<a name="line32"></a> * An implementation of a menu that can attach itself to DOM element that
<a name="line33"></a> * are annotated appropriately.
<a name="line34"></a> *
<a name="line35"></a> * The following attributes are used by the AttachableMenu
<a name="line36"></a> *
<a name="line37"></a> * menu-item - Should be set on DOM elements that function as items in the
<a name="line38"></a> * menu that can be selected.
<a name="line39"></a> * classNameSelected - A class that will be added to the element&#39;s class names
<a name="line40"></a> * when the item is selected via keyboard or mouse.
<a name="line41"></a> *
<a name="line42"></a> * @param {Element=} opt_element A DOM element for the popup.
<a name="line43"></a> * @constructor
<a name="line44"></a> * @extends {goog.ui.MenuBase}
<a name="line45"></a> * @deprecated Use goog.ui.PopupMenu.
<a name="line46"></a> */
<a name="line47"></a>goog.ui.AttachableMenu = function(opt_element) {
<a name="line48"></a>  goog.ui.MenuBase.call(this, opt_element);
<a name="line49"></a>};
<a name="line50"></a>goog.inherits(goog.ui.AttachableMenu, goog.ui.MenuBase);
<a name="line51"></a>
<a name="line52"></a>
<a name="line53"></a>/**
<a name="line54"></a> * The currently selected element (mouse was moved over it or keyboard arrows)
<a name="line55"></a> * @type {Element}
<a name="line56"></a> * @private
<a name="line57"></a> */
<a name="line58"></a>goog.ui.AttachableMenu.prototype.selectedElement_ = null;
<a name="line59"></a>
<a name="line60"></a>
<a name="line61"></a>/**
<a name="line62"></a> * Class name to append to a menu item&#39;s class when it&#39;s selected
<a name="line63"></a> * @type {string}
<a name="line64"></a> * @private
<a name="line65"></a> */
<a name="line66"></a>goog.ui.AttachableMenu.prototype.itemClassName_ = &#39;menu-item&#39;;
<a name="line67"></a>
<a name="line68"></a>
<a name="line69"></a>/**
<a name="line70"></a> * Class name to append to a menu item&#39;s class when it&#39;s selected
<a name="line71"></a> * @type {string}
<a name="line72"></a> * @private
<a name="line73"></a> */
<a name="line74"></a>goog.ui.AttachableMenu.prototype.selectedItemClassName_ = &#39;menu-item-selected&#39;;
<a name="line75"></a>
<a name="line76"></a>
<a name="line77"></a>/**
<a name="line78"></a> * Keep track of when the last key was pressed so that a keydown-scroll doesn&#39;t
<a name="line79"></a> * trigger a mouseover event
<a name="line80"></a> * @type {number}
<a name="line81"></a> * @private
<a name="line82"></a> */
<a name="line83"></a>goog.ui.AttachableMenu.prototype.lastKeyDown_ = goog.now();
<a name="line84"></a>
<a name="line85"></a>
<a name="line86"></a>/** @override */
<a name="line87"></a>goog.ui.AttachableMenu.prototype.disposeInternal = function() {
<a name="line88"></a>  goog.ui.AttachableMenu.superClass_.disposeInternal.call(this);
<a name="line89"></a>  this.selectedElement_ = null;
<a name="line90"></a>};
<a name="line91"></a>
<a name="line92"></a>
<a name="line93"></a>/**
<a name="line94"></a> * Sets the class name to use for menu items
<a name="line95"></a> *
<a name="line96"></a> * @return {string} The class name to use for items.
<a name="line97"></a> */
<a name="line98"></a>goog.ui.AttachableMenu.prototype.getItemClassName = function() {
<a name="line99"></a>  return this.itemClassName_;
<a name="line100"></a>};
<a name="line101"></a>
<a name="line102"></a>
<a name="line103"></a>/**
<a name="line104"></a> * Sets the class name to use for menu items
<a name="line105"></a> *
<a name="line106"></a> * @param {string} name The class name to use for items.
<a name="line107"></a> */
<a name="line108"></a>goog.ui.AttachableMenu.prototype.setItemClassName = function(name) {
<a name="line109"></a>  this.itemClassName_ = name;
<a name="line110"></a>};
<a name="line111"></a>
<a name="line112"></a>
<a name="line113"></a>/**
<a name="line114"></a> * Sets the class name to use for selected menu items
<a name="line115"></a> * todo(user) - reevaluate if we can simulate pseudo classes in IE
<a name="line116"></a> *
<a name="line117"></a> * @return {string} The class name to use for selected items.
<a name="line118"></a> */
<a name="line119"></a>goog.ui.AttachableMenu.prototype.getSelectedItemClassName = function() {
<a name="line120"></a>  return this.selectedItemClassName_;
<a name="line121"></a>};
<a name="line122"></a>
<a name="line123"></a>
<a name="line124"></a>/**
<a name="line125"></a> * Sets the class name to use for selected menu items
<a name="line126"></a> * todo(user) - reevaluate if we can simulate pseudo classes in IE
<a name="line127"></a> *
<a name="line128"></a> * @param {string} name The class name to use for selected items.
<a name="line129"></a> */
<a name="line130"></a>goog.ui.AttachableMenu.prototype.setSelectedItemClassName = function(name) {
<a name="line131"></a>  this.selectedItemClassName_ = name;
<a name="line132"></a>};
<a name="line133"></a>
<a name="line134"></a>
<a name="line135"></a>/**
<a name="line136"></a> * Returns the selected item
<a name="line137"></a> *
<a name="line138"></a> * @return {Element} The item selected or null if no item is selected.
<a name="line139"></a> * @override
<a name="line140"></a> */
<a name="line141"></a>goog.ui.AttachableMenu.prototype.getSelectedItem = function() {
<a name="line142"></a>  return this.selectedElement_;
<a name="line143"></a>};
<a name="line144"></a>
<a name="line145"></a>
<a name="line146"></a>/** @override */
<a name="line147"></a>goog.ui.AttachableMenu.prototype.setSelectedItem = function(obj) {
<a name="line148"></a>  var elt = /** @type {Element} */ (obj);
<a name="line149"></a>  if (this.selectedElement_) {
<a name="line150"></a>    goog.dom.classes.remove(this.selectedElement_, this.selectedItemClassName_);
<a name="line151"></a>  }
<a name="line152"></a>
<a name="line153"></a>  this.selectedElement_ = elt;
<a name="line154"></a>
<a name="line155"></a>  var el = this.getElement();
<a name="line156"></a>  goog.asserts.assert(el, &#39;The attachable menu DOM element cannot be null.&#39;);
<a name="line157"></a>  if (this.selectedElement_) {
<a name="line158"></a>    goog.dom.classes.add(this.selectedElement_, this.selectedItemClassName_);
<a name="line159"></a>
<a name="line160"></a>    if (elt.id) {
<a name="line161"></a>      // Update activedescendant to reflect the new selection. ARIA roles for
<a name="line162"></a>      // menu and menuitem can be set statically (thru Soy templates, for
<a name="line163"></a>      // example) whereas this needs to be updated as the selection changes.
<a name="line164"></a>      goog.a11y.aria.setState(el, goog.a11y.aria.State.ACTIVEDESCENDANT,
<a name="line165"></a>          elt.id);
<a name="line166"></a>    }
<a name="line167"></a>
<a name="line168"></a>    var top = this.selectedElement_.offsetTop;
<a name="line169"></a>    var height = this.selectedElement_.offsetHeight;
<a name="line170"></a>    var scrollTop = el.scrollTop;
<a name="line171"></a>    var scrollHeight = el.offsetHeight;
<a name="line172"></a>
<a name="line173"></a>    // If the menu is scrollable this scrolls the selected item into view
<a name="line174"></a>    // (this has no effect when the menu doesn&#39;t scroll)
<a name="line175"></a>    if (top &lt; scrollTop) {
<a name="line176"></a>      el.scrollTop = top;
<a name="line177"></a>    } else if (top + height &gt; scrollTop + scrollHeight) {
<a name="line178"></a>      el.scrollTop = top + height - scrollHeight;
<a name="line179"></a>    }
<a name="line180"></a>  } else {
<a name="line181"></a>    // Clear off activedescendant to reflect no selection.
<a name="line182"></a>    goog.a11y.aria.setState(el, goog.a11y.aria.State.ACTIVEDESCENDANT, &#39;&#39;);
<a name="line183"></a>  }
<a name="line184"></a>};
<a name="line185"></a>
<a name="line186"></a>
<a name="line187"></a>/** @override */
<a name="line188"></a>goog.ui.AttachableMenu.prototype.showPopupElement = function() {
<a name="line189"></a>  // The scroll position cannot be set for hidden (display: none) elements in
<a name="line190"></a>  // gecko browsers.
<a name="line191"></a>  var el = /** @type {Element} */ (this.getElement());
<a name="line192"></a>  goog.style.showElement(el, true);
<a name="line193"></a>  el.scrollTop = 0;
<a name="line194"></a>  el.style.visibility = &#39;visible&#39;;
<a name="line195"></a>};
<a name="line196"></a>
<a name="line197"></a>
<a name="line198"></a>/**
<a name="line199"></a> * Called after the menu is shown.
<a name="line200"></a> * @protected
<a name="line201"></a> * @suppress {underscore}
<a name="line202"></a> * @override
<a name="line203"></a> */
<a name="line204"></a>goog.ui.AttachableMenu.prototype.onShow_ = function() {
<a name="line205"></a>  goog.ui.AttachableMenu.superClass_.onShow_.call(this);
<a name="line206"></a>
<a name="line207"></a>  // In IE, focusing the menu causes weird scrolling to happen. Focusing the
<a name="line208"></a>  // first child makes the scroll behavior better, and the key handling still
<a name="line209"></a>  // works. In FF, focusing the first child causes us to lose key events, so we
<a name="line210"></a>  // still focus the menu.
<a name="line211"></a>  var el = this.getElement();
<a name="line212"></a>  goog.userAgent.IE ? el.firstChild.focus() :
<a name="line213"></a>      el.focus();
<a name="line214"></a>};
<a name="line215"></a>
<a name="line216"></a>
<a name="line217"></a>/**
<a name="line218"></a> * Returns the next or previous item. Used for up/down arrows.
<a name="line219"></a> *
<a name="line220"></a> * @param {boolean} prev True to go to the previous element instead of next.
<a name="line221"></a> * @return {Element} The next or previous element.
<a name="line222"></a> * @protected
<a name="line223"></a> */
<a name="line224"></a>goog.ui.AttachableMenu.prototype.getNextPrevItem = function(prev) {
<a name="line225"></a>  // first find the index of the next element
<a name="line226"></a>  var elements = this.getElement().getElementsByTagName(&#39;*&#39;);
<a name="line227"></a>  var elementCount = elements.length;
<a name="line228"></a>  var index;
<a name="line229"></a>  // if there is a selected element, find its index and then inc/dec by one
<a name="line230"></a>  if (this.selectedElement_) {
<a name="line231"></a>    for (var i = 0; i &lt; elementCount; i++) {
<a name="line232"></a>      if (elements[i] == this.selectedElement_) {
<a name="line233"></a>        index = prev ? i - 1 : i + 1;
<a name="line234"></a>        break;
<a name="line235"></a>      }
<a name="line236"></a>    }
<a name="line237"></a>  }
<a name="line238"></a>
<a name="line239"></a>  // if no selected element, start from beginning or end
<a name="line240"></a>  if (!goog.isDef(index)) {
<a name="line241"></a>    index = prev ? elementCount - 1 : 0;
<a name="line242"></a>  }
<a name="line243"></a>
<a name="line244"></a>  // iterate forward or backwards through the elements finding the next
<a name="line245"></a>  // menu item
<a name="line246"></a>  for (var i = 0; i &lt; elementCount; i++) {
<a name="line247"></a>    var multiplier = prev ? -1 : 1;
<a name="line248"></a>    var nextIndex = index + (multiplier * i) % elementCount;
<a name="line249"></a>
<a name="line250"></a>    // if overflowed/underflowed, wrap around
<a name="line251"></a>    if (nextIndex &lt; 0) {
<a name="line252"></a>      nextIndex += elementCount;
<a name="line253"></a>    } else if (nextIndex &gt;= elementCount) {
<a name="line254"></a>      nextIndex -= elementCount;
<a name="line255"></a>    }
<a name="line256"></a>
<a name="line257"></a>    if (this.isMenuItem_(elements[nextIndex])) {
<a name="line258"></a>      return elements[nextIndex];
<a name="line259"></a>    }
<a name="line260"></a>  }
<a name="line261"></a>  return null;
<a name="line262"></a>};
<a name="line263"></a>
<a name="line264"></a>
<a name="line265"></a>/**
<a name="line266"></a> * Mouse over handler for the menu.
<a name="line267"></a> * @param {goog.events.Event} e The event object.
<a name="line268"></a> * @protected
<a name="line269"></a> * @override
<a name="line270"></a> */
<a name="line271"></a>goog.ui.AttachableMenu.prototype.onMouseOver = function(e) {
<a name="line272"></a>  var eltItem = this.getAncestorMenuItem_(/** @type {Element} */ (e.target));
<a name="line273"></a>  if (eltItem == null) {
<a name="line274"></a>    return;
<a name="line275"></a>  }
<a name="line276"></a>
<a name="line277"></a>  // Stop the keydown triggering a mouseover in FF.
<a name="line278"></a>  if (goog.now() - this.lastKeyDown_ &gt; goog.ui.PopupBase.DEBOUNCE_DELAY_MS) {
<a name="line279"></a>    this.setSelectedItem(eltItem);
<a name="line280"></a>  }
<a name="line281"></a>};
<a name="line282"></a>
<a name="line283"></a>
<a name="line284"></a>/**
<a name="line285"></a> * Mouse out handler for the menu.
<a name="line286"></a> * @param {goog.events.Event} e The event object.
<a name="line287"></a> * @protected
<a name="line288"></a> * @override
<a name="line289"></a> */
<a name="line290"></a>goog.ui.AttachableMenu.prototype.onMouseOut = function(e) {
<a name="line291"></a>  var eltItem = this.getAncestorMenuItem_(/** @type {Element} */ (e.target));
<a name="line292"></a>  if (eltItem == null) {
<a name="line293"></a>    return;
<a name="line294"></a>  }
<a name="line295"></a>
<a name="line296"></a>  // Stop the keydown triggering a mouseout in FF.
<a name="line297"></a>  if (goog.now() - this.lastKeyDown_ &gt; goog.ui.PopupBase.DEBOUNCE_DELAY_MS) {
<a name="line298"></a>    this.setSelectedItem(null);
<a name="line299"></a>  }
<a name="line300"></a>};
<a name="line301"></a>
<a name="line302"></a>
<a name="line303"></a>/**
<a name="line304"></a> * Mouse down handler for the menu. Prevents default to avoid text selection.
<a name="line305"></a> * @param {!goog.events.Event} e The event object.
<a name="line306"></a> * @protected
<a name="line307"></a> * @override
<a name="line308"></a> */
<a name="line309"></a>goog.ui.AttachableMenu.prototype.onMouseDown = goog.events.Event.preventDefault;
<a name="line310"></a>
<a name="line311"></a>
<a name="line312"></a>/**
<a name="line313"></a> * Mouse up handler for the menu.
<a name="line314"></a> * @param {goog.events.Event} e The event object.
<a name="line315"></a> * @protected
<a name="line316"></a> * @override
<a name="line317"></a> */
<a name="line318"></a>goog.ui.AttachableMenu.prototype.onMouseUp = function(e) {
<a name="line319"></a>  var eltItem = this.getAncestorMenuItem_(/** @type {Element} */ (e.target));
<a name="line320"></a>  if (eltItem == null) {
<a name="line321"></a>    return;
<a name="line322"></a>  }
<a name="line323"></a>  this.setVisible(false);
<a name="line324"></a>  this.onItemSelected_(eltItem);
<a name="line325"></a>};
<a name="line326"></a>
<a name="line327"></a>
<a name="line328"></a>/**
<a name="line329"></a> * Key down handler for the menu.
<a name="line330"></a> * @param {goog.events.KeyEvent} e The event object.
<a name="line331"></a> * @protected
<a name="line332"></a> * @override
<a name="line333"></a> */
<a name="line334"></a>goog.ui.AttachableMenu.prototype.onKeyDown = function(e) {
<a name="line335"></a>  switch (e.keyCode) {
<a name="line336"></a>    case goog.events.KeyCodes.DOWN:
<a name="line337"></a>      this.setSelectedItem(this.getNextPrevItem(false));
<a name="line338"></a>      this.lastKeyDown_ = goog.now();
<a name="line339"></a>      break;
<a name="line340"></a>    case goog.events.KeyCodes.UP:
<a name="line341"></a>      this.setSelectedItem(this.getNextPrevItem(true));
<a name="line342"></a>      this.lastKeyDown_ = goog.now();
<a name="line343"></a>      break;
<a name="line344"></a>    case goog.events.KeyCodes.ENTER:
<a name="line345"></a>      if (this.selectedElement_) {
<a name="line346"></a>        this.onItemSelected_();
<a name="line347"></a>        this.setVisible(false);
<a name="line348"></a>      }
<a name="line349"></a>      break;
<a name="line350"></a>    case goog.events.KeyCodes.ESC:
<a name="line351"></a>      this.setVisible(false);
<a name="line352"></a>      break;
<a name="line353"></a>    default:
<a name="line354"></a>      if (e.charCode) {
<a name="line355"></a>        var charStr = String.fromCharCode(e.charCode);
<a name="line356"></a>        this.selectByName_(charStr, 1, true);
<a name="line357"></a>      }
<a name="line358"></a>      break;
<a name="line359"></a>  }
<a name="line360"></a>  // Prevent the browser&#39;s default keydown behaviour when the menu is open,
<a name="line361"></a>  // e.g. keyboard scrolling.
<a name="line362"></a>  e.preventDefault();
<a name="line363"></a>
<a name="line364"></a>  // Stop propagation to prevent application level keyboard shortcuts from
<a name="line365"></a>  // firing.
<a name="line366"></a>  e.stopPropagation();
<a name="line367"></a>
<a name="line368"></a>  this.dispatchEvent(e);
<a name="line369"></a>};
<a name="line370"></a>
<a name="line371"></a>
<a name="line372"></a>/**
<a name="line373"></a> * Find an item that has the given prefix and select it.
<a name="line374"></a> *
<a name="line375"></a> * @param {string} prefix The entered prefix, so far.
<a name="line376"></a> * @param {number=} opt_direction 1 to search forward from the selection
<a name="line377"></a> *     (default), -1 to search backward (e.g. to go to the previous match).
<a name="line378"></a> * @param {boolean=} opt_skip True if should skip the current selection,
<a name="line379"></a> *     unless no other item has the given prefix.
<a name="line380"></a> * @private
<a name="line381"></a> */
<a name="line382"></a>goog.ui.AttachableMenu.prototype.selectByName_ =
<a name="line383"></a>    function(prefix, opt_direction, opt_skip) {
<a name="line384"></a>  var elements = this.getElement().getElementsByTagName(&#39;*&#39;);
<a name="line385"></a>  var elementCount = elements.length;
<a name="line386"></a>  var index;
<a name="line387"></a>
<a name="line388"></a>  if (elementCount == 0) {
<a name="line389"></a>    return;
<a name="line390"></a>  }
<a name="line391"></a>
<a name="line392"></a>  if (!this.selectedElement_ ||
<a name="line393"></a>      (index = goog.array.indexOf(elements, this.selectedElement_)) == -1) {
<a name="line394"></a>    // no selection or selection isn&#39;t known =&gt; start at the beginning
<a name="line395"></a>    index = 0;
<a name="line396"></a>  }
<a name="line397"></a>
<a name="line398"></a>  var start = index;
<a name="line399"></a>  var re = new RegExp(&#39;^&#39; + goog.string.regExpEscape(prefix), &#39;i&#39;);
<a name="line400"></a>  var skip = opt_skip &amp;&amp; this.selectedElement_;
<a name="line401"></a>  var dir = opt_direction || 1;
<a name="line402"></a>
<a name="line403"></a>  do {
<a name="line404"></a>    if (elements[index] != skip &amp;&amp; this.isMenuItem_(elements[index])) {
<a name="line405"></a>      var name = goog.dom.getTextContent(elements[index]);
<a name="line406"></a>      if (name.match(re)) {
<a name="line407"></a>        break;
<a name="line408"></a>      }
<a name="line409"></a>    }
<a name="line410"></a>    index += dir;
<a name="line411"></a>    if (index == elementCount) {
<a name="line412"></a>      index = 0;
<a name="line413"></a>    } else if (index &lt; 0) {
<a name="line414"></a>      index = elementCount - 1;
<a name="line415"></a>    }
<a name="line416"></a>  } while (index != start);
<a name="line417"></a>
<a name="line418"></a>  if (this.selectedElement_ != elements[index]) {
<a name="line419"></a>    this.setSelectedItem(elements[index]);
<a name="line420"></a>  }
<a name="line421"></a>};
<a name="line422"></a>
<a name="line423"></a>
<a name="line424"></a>/**
<a name="line425"></a> * Dispatch an ITEM_ACTION event when an item is selected
<a name="line426"></a> * @param {Object=} opt_item Item selected.
<a name="line427"></a> * @private
<a name="line428"></a> */
<a name="line429"></a>goog.ui.AttachableMenu.prototype.onItemSelected_ = function(opt_item) {
<a name="line430"></a>  this.dispatchEvent(new goog.ui.ItemEvent(goog.ui.MenuBase.Events.ITEM_ACTION,
<a name="line431"></a>      this, opt_item || this.selectedElement_));
<a name="line432"></a>};
<a name="line433"></a>
<a name="line434"></a>
<a name="line435"></a>/**
<a name="line436"></a> * Returns whether the specified element is a menu item.
<a name="line437"></a> * @param {Element|undefined} elt The element to find a menu item ancestor of.
<a name="line438"></a> * @return {boolean} Whether the specified element is a menu item.
<a name="line439"></a> * @private
<a name="line440"></a> */
<a name="line441"></a>goog.ui.AttachableMenu.prototype.isMenuItem_ = function(elt) {
<a name="line442"></a>  return !!elt &amp;&amp; goog.dom.classes.has(elt, this.itemClassName_);
<a name="line443"></a>};
<a name="line444"></a>
<a name="line445"></a>
<a name="line446"></a>/**
<a name="line447"></a> * Returns the menu-item scoping the specified element, or null if there is
<a name="line448"></a> * none.
<a name="line449"></a> * @param {Element|undefined} elt The element to find a menu item ancestor of.
<a name="line450"></a> * @return {Element} The menu-item scoping the specified element, or null if
<a name="line451"></a> *     there is none.
<a name="line452"></a> * @private
<a name="line453"></a> */
<a name="line454"></a>goog.ui.AttachableMenu.prototype.getAncestorMenuItem_ = function(elt) {
<a name="line455"></a>  if (elt) {
<a name="line456"></a>    var ownerDocumentBody = goog.dom.getOwnerDocument(elt).body;
<a name="line457"></a>    while (elt != null &amp;&amp; elt != ownerDocumentBody) {
<a name="line458"></a>      if (this.isMenuItem_(elt)) {
<a name="line459"></a>        return elt;
<a name="line460"></a>      }
<a name="line461"></a>      elt = /** @type {Element} */ (elt.parentNode);
<a name="line462"></a>    }
<a name="line463"></a>  }
<a name="line464"></a>  return null;
<a name="line465"></a>};
</pre>


</body>
</html>
